<template>
	<view class="content">
		<view class="code">
			<!--			<view class="user">-->
			<!--				<image class="avatar" src="http://sni1muz85.hd-bkt.clouddn.com/img/my/avatar.jpeg"></image>-->
			<!--				<text class="name">用户名</text>-->
			<!--			</view>-->
			<image show-menu-by-longpress="true" class="img" src="http://sni1muz85.hd-bkt.clouddn.com/img/index/wx.jpg">
			</image>
			<text class="text">长按识别二维码，添加好友</text>
		</view>

		<view class="line">
			<view class="left">
				<view class="icon">
					<image src="http://sni1muz85.hd-bkt.clouddn.com/img/icons/service.png"></image>
				</view>
				<view class="text">客服微信： {{ serviceWechat }}</view>
			</view>
			<view class="btn" @click="onCopy(serviceWechat)">
				复制
			</view>
		</view>

		<view class="line">
			<view class="left">
				<view class="icon" style="background-color: #FF8C2B;">
					<image :src="serviceImage"></image>
				</view>
				<view class="text">客服电话： {{servicePhone}}</view>
			</view>
			<view class="btn" @click="callPhone(servicePhone)">
				拨打
			</view>
		</view>

		<button class="button" open-type="contact" bindcontact="handleContact">在线客服</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wx: "",
				phone: "",
				serviceImage: "",
				servicePhone: "",
				serviceWechat: ""
			}
		},
		onShow() {
			this.getapi_get()
		},
		methods: {
			getapi_get() {
				this.$api.request({
					url: this.$api.getkefuinner
				}).then((res) => {
					this.serviceImage = res.data.serviceImage
					this.servicePhone = res.data.servicePhone
					this.serviceWechat = res.data.serviceWechat
				})
			},
			// 复制文字
			onCopy(text) {
				uni.setClipboardData({
					data: that.serviceWechat,
					success: function() {
						uni.showToast({
							title: "复制成功",
						})
					},
					fail: (res => {
						console.log(res)
					})
				});

			},
			handleContact(e) {
				console.log(e.detail.path)
				console.log(e.detail.query)
			},
			callPhone(phone) {
				wx.makePhoneCall({
					phoneNumber: that.servicePhone,
					success: function(res) {
						console.log('拨打电话成功！');
					},
					fail: function(res) {
						console.log('拨打电话失败！');
					}
				})
			}
		}

	}
</script>

<style lang="less" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;

		.code {
			width: 92vw;
			display: flex;
			flex-direction: column;
			align-items: center;
			background-color: #fff;
			margin-top: 30rpx;

			.user {
				width: 400rpx;
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				.avatar {
					height: 70rpx;
					width: 70rpx;
					border-radius: 15rpx;
				}

				.name {
					font-size: 38rpx;
					font-weight: bold;
					margin-left: 20rpx;
				}
			}

			.img {
				height: 700rpx;
				width: 600rpx;
				margin-top: 30rpx;
			}

			.text {
				font-size: 32rpx;
				margin-top: 20rpx;
				color: #07C160;
				margin-top: 20rpx;
				margin-bottom: 50rpx;
			}
		}

		.line {
			width: 92vw;
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: #fff;
			margin-top: 20rpx;
			padding: 20rpx 0;

			.left {
				display: flex;
				align-items: center;
				margin-left: 30rpx;

				.icon {
					height: 70rpx;
					width: 70rpx;
					border-radius: 50%;
					background-color: #07C160;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						height: 50rpx;
						width: 50rpx;
						border-radius: 50%;
					}
				}

				.text {
					font-size: 32rpx;
					font-weight: bold;
					margin-left: 20rpx;
				}
			}

			.btn {
				font-size: 32rpx;
				color: #fff;
				padding: 10rpx 30rpx;
				background-color: #07C160;
				border-radius: 8rpx;
				margin-right: 30rpx;
			}
		}

		.button {
			width: 200rpx;
			text-align: center;
			font-size: 32rpx;
			color: #fff;
			padding: 20rpx 30rpx;
			background-color: #07C160;
			border-radius: 15rpx;
			//margin-right: 30rpx;
			margin-top: 50rpx;
		}
	}
</style>